<!DOCTYPE html>

<html>

<head>
    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>后台管理</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入样式 -->

    <link rel="stylesheet" href="../plugins/elementui/index.css">

    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">

    <link rel="stylesheet" href="../css/mystyle.css">
    <!-- 引入组件库 -->

    <script src="../js/vue.js"></script>

    <script src="../plugins/elementui/index.js"></script>

    <script type="text/javascript" src="../js/jquery.min.js"></script>

    <script src="../js/axios-0.18.0.js"></script>

    <script src="../http/request.js"></script>

    <script src="../utils/dateFormat.js"></script> 

    <style>
        .margin-left-small {
            margin-left: 20px;
        }
    </style>
</head>

<body class="hold-transition">
    <div id="app">
        <div class="app-container">
            <div class="box">

                <div class="filter-container">

                    <el-input placeholder="productId" v-model="pagination.queryString" style="width: 200px;"
                        class="filter-item"></el-input>

                    <div class="margin-left-small">
                        <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期" >
                        </el-date-picker>
                    </div>

                    <el-button type="primary" class="margin-left-small" @click="getByCondition()"
                        class="dalfBut">查询</el-button>
                </div>

                <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                    <el-table-column prop="id" type="index" align="center" label="序号"></el-table-column>

                    <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>

                    <el-table-column prop="packageInfo" label="账号密码" align="center"></el-table-column>

                    <el-table-column prop="remark" label="课程名" align="center"></el-table-column>

                    <el-table-column prop="phone" label="联系电话" align="center"></el-table-column>

                    <!-- 跑跑币-->
                    <el-table-column prop="productId" label="刷课类型" align="center"></el-table-column>

                    <el-table-column label="操作" align="center">

                        <template slot-scope="scope">

                            <!-- <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button> -->
                            <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
                        </template>

                    </el-table-column>

                </el-table>

            </div>

        </div>

    </div>

</body>



<script>
    var vue = new Vue({

        el: '#app',
        data: {
            value1: '',
            pagination: {},
            dataList: [],//当前页要展示的列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//控制表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                type: [{ required: true, message: '帮手类别为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '帮手电话号为必填项', trigger: 'blur' }]
            }
        },

        //钩子函数，VUE对象初始化完成后自动执行
        mounted() {
            this.getAll();
        },
        methods: {
            //列表
            getAll() {
                //发送ajax请求
                axios.get("/lesson/getAll").then((res) => {
                    console.log(res.data)
                    this.dataList = res.data;
                    // console.log("dataList" + JSON.stringify(this.dataList))
                });
            },

            //根据手机号查询
            handleSizeChange: function (val) {
                alert("每页记录数变化" + val)
            },
            handleCurrentChange: function (val) {
                alert("页码发生变化" + val)
            },
            getByCondition() {
                // start = this.convert(this.value1[0])
                // end = this.convert(this.value1[1])
                let start
                let end
                if(typeof(this.value1[0]) == "undefined"){
                    start = null
                }else{
                    start = this.convert(this.value1[0])
                }

                if(typeof(this.value1[0]) == "undefined"){
                    end = null
                }else{
                    end = this.convert(this.value1[1])
                }

                console.log(start)
                console.log(end)
                let productId = 0
                if(typeof(this.pagination.queryString) == "undefined"){
                    productId = null
                }else{
                    productId = this.pagination.queryString
                }

                //发送ajax请求
                axios.get("/lesson/getByCondition?productId=" + productId+"&start="+start+"&end="+end).then((res) => {
                    console.log(this.pagination.queryString)
                    console.log(res)
                    this.dataList = res.data;
                });
            },
            convert(time){
                const date = new Date(time)
                return date.getTime();
            },
            //弹出编辑窗口
            handleUpdate(row) {
                // console.log(row);   //row.id 查询条件
                //查询数据，根据id查询
                axios.get("/order/getEditInfo?id=" + row.id).then((res) => {
                    // console.log("formdata" + JSON.stringify(this.formData))
                    // console.log(res.data.data);
                    // console.log(res.data)
                    if (res.code === 1) {
                        // console.log(res)
                        //展示弹层，加载数据
                        this.dialogFormVisible4Edit = true;
                        this.formData = res.data;
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            },
            // 删除
            handleDelete(row) {
                console.log(row.id)
                //1.弹出提示框
                this.$confirm("此操作永久删除当前数据，是否继续？", "提示", {
                    type: 'info'
                }).then(() => {
                    //2.做删除业务
                    axios.delete(`/lesson/deleteById/${row.id}` ).then((res) => {
                        console.log(res)
                        if (res.code === 1) {
                            this.$message.success("删除成功");
                        } else {
                            this.$message.error("删除失败");
                        }
                    }).finally(() => {
                        this.getAll();
                    });
                }).catch(() => {
                    //3.取消删除
                    this.$message.info("取消删除操作");
                });
            },
            //编辑
            handleEdit() {
                //发送ajax请求
                axios.put("/order/updateEditInfo", this.formData).then((res) => {
                    console.log(this.formData)

                    //如果操作成功，关闭弹层，显示数据
                    if (res.code === 1) {
                        this.dialogFormVisible4Edit = false;
                        this.$message.success("修改成功");
                    } else if (res.code === 0) {
                        this.$message.error(res.msg);
                    } else {
                        this.$message.error(res.msg);
                    }
                }).finally(() => {
                    this.getAll();
                });
            },
        },
    })

</script>

</html>